<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* popup form that loads record information (structure) from remote heurist instance and save
* the record data as email to this remote instance
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  Export
*/

-->

<html>
 <head>
  <title>Email record</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">

  <link rel=stylesheet href="../../common/css/global.css">
  <link rel=stylesheet href="../../common/css/edit.css">
  <link rel=stylesheet href="../../common/css/admin.css">
 <!--
<script type="text/javascript" src="../../external/yui/2.8.2r1/build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="../../external/yui/2.8.2r1/build/json/json-min.js"></script> -->

	<style>
		.greyButton {
			background-image: url("../../common/images/bug_off.png");
			background-repeat: no-repeat;
			background-position: 0 -1px;
			padding: 0 6px 0 20px;
			line-height: 19px;
		}

	</style>

 </head>

 <body class="popup" width="600" height="500" style="overflow:hidden;">
  <script type="text/javascript" src="../../common/js/utilsLoad.js"></script>
  <script type="text/javascript" src="../../common/js/utilsUI.js"></script>
  <script type="text/javascript" src="../../common/php/displayPreferences.php"></script>
  <script type="text/javascript" src="../../external/php/sysinfo.php"></script>

<div class="header"><b><span id=rectype-val></span></b><span id=title-val></span></div>
<div id="results"><iframe frameborder=0 class=tab id=edit-frame style="width: 100%; height: 100%;"></iframe></div>
<div id="add_records_footer" style="width:100%;text-align: center;height:30px">
	<input id="btnSubmit" type=button onClick="window.HEURIST.edit.save();" value="Email record" class="greyButton" style="padding-left: 20px !important;">
</div>

  <script type="text/javascript">

// object to manage this popup form
window.HEURIST.edit = {
	publicHasChanged: false,

	unchanged: function() {
		window.HEURIST.edit.publicHasChanged = false;
	},

	changed: function() {
		window.HEURIST.edit.publicHasChanged = true;
	},

	save: function() {

		//
		// change attribute of form from saveRecordDetails to emailRecordDetails
		//
		var editFrame = document.getElementById("edit-frame");
		var contentWindow = editFrame.contentWindow;
		if (contentWindow) {
			var form = contentWindow.document.forms[0];
			var db = (window.HEURIST.parameters["db"] || "");

			if(form.setAttribute){
			 	form.setAttribute("jsonAction", top.HEURIST.basePath+'export/email/emailRecordDetails.php?db='+db);
			}
			form.action = top.HEURIST.basePath+'export/email/emailRecordDetails.php?db='+db;

			if (form.onsubmit  &&  ! form.onsubmit()) {
				return;	// submit failed ... up to the individual form handlers to display messages
			}
			top.HEURIST.registerEvent(editFrame, "load", function() {
				alert('Email sent');
				window.close();
				//window.close(parent.HEURIST.record.title, parent.HEURIST.record.bdValuesByType, parent.HEURIST.record.bibID);
			});


			(form.heuristSubmit || form.submit)();
			//form.submit();
			return;
		}
	}
};

	if(!top.HEURIST.edit){
		//for admin part - editRecord.js is not loaded initially
		top.HEURIST.loadScript(top.HEURIST.basePath+"records/edit/editRecord.js");		// edit-specific HEURIST functions
	}


	//
	// detect what rectype user has to fill and send by email
	//
	window.HEURIST.parameters = top.HEURIST.parseParams(window.location.search);

	var editFrame = document.getElementById("edit-frame");
	var db = (window.HEURIST.parameters["db"] || "");

	var sparam = window.HEURIST.parameters["rectype"];
	//var rectype = parseInt(sparam);

	if(sparam==="bugreport"){

		document.title = "Bug report / feature request";
		document.getElementById("btnSubmit").value = "Send to Heurist development team";

/*
		var rectype = 253; //253 MAGIC

var rectype_bugreport = {"dtFields":{"179":["Bug Title","Specify short name for bug",null,"","required","1","1","60","0","000","1",null,null,"",null,"open",null,null,null],"191":["Bug description","Detail description of bug",null,"","optional","1","0","60","0","001","1",null,null,null,null,"open",null,null,null],"259":["Steps to reproduce","Describe what actions you took to obtain the bug",null,"","optional","1","0","60","0","002","1",null,null,null,null,"open",null,null,null],"221":["Screenshot","Make a screenshot of bug and browser this image file",null,"","optional","5","0","60","0","004","1",null,null,"",null,"open",null,null,null]},"commonFields":["Bug submit","bug report","normal","0","[Title / Name]","","Bug submits","1","open","7","0","",""]};

//"559":["Category-for-documentation","Category-for-documentation",null,"","optional","1","0","60","0","003","1","{\"631\":{},\"633\":{},\"634\":{},\"635\":{},\"636\":{},\"637\":{},\"638\":{}}",null,"[]",null,"open",null,null,null],

top.HEURIST.rectypes.typedefs[rectype] = rectype_bugreport;
top.HEURIST.rectypes.names[rectype] = 'Bug report';
top.HEURIST.rectypes.pluralNames[rectype] = 'Bug reportS';
top.HEURIST.rectypes.dtDisplayOrder[rectype] = ["179","191","259","221"]; //"559",
*/
		editFrame.src = "../../export/email/formBugReport.php?db="+db;
		editFrame.style.display = "block";

	}else{

		var titleBits = (window.HEURIST.parameters["title"] || "").split(/\s+/);
		for (var i=0; i < titleBits.length; ++i) {
			titleBits[i] = titleBits[i].charAt(0).toUpperCase() + titleBits[i].substring(1);
		}
		var title = titleBits.join(" ");
		document.getElementById("title-val").appendChild(document.createTextNode(title || ""));
		var url = window.HEURIST.parameters["url"];

		editFrame.src = "../../records/edit/tabs/publicInfoTab.html?db="+db+"&rectype="+rectype+"&title="+encodeURIComponent(title);
		editFrame.style.display = "block";

		//name of record type in the header of form
		document.getElementById("rectype-val").appendChild(document.createTextNode(top.HEURIST.rectypes.names[rectype]));

	}

</script>

 </body>
</html>
